.TH std::basic_istream::unget 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_istream::unget \- std::basic_istream::unget

.SH Synopsis
   basic_istream& unget();

   Makes the most recently extracted character available again.

   First, clears eofbit. Then,
   \fI(since C++11)\fP unget behaves as UnformattedInputFunction. After constructing and
   checking the sentry object, if any ios_base::iostate flags are set, the function
   sets failbit and returns. Otherwise, calls rdbuf()->sungetc().

   If rdbuf()->sungetc() returns Traits::eof(), calls setstate(badbit).

   In any case, sets the gcount() counter to zero.

.SH Parameters

   \fI(none)\fP

.SH Return value

   *this

.SH Exceptions


   failure if an error occurred (the error state flag is not goodbit) and exceptions()
   is set to throw for that state.

   If an internal operation throws an exception, it is caught and badbit is set. If
   exceptions() is set for badbit, the exception is rethrown.

.SH Example


// Run this code

 #include <iostream>
 #include <sstream>

 int main()
 {
     std::istringstream s1("Hello, world.");
     char c1 = s1.get();
     if (s1.unget())
     {
         char c2 = s1.get();
         std::cout << "Got: '" << c1 << "'. Got again: '" << c2 << "'.\\n";
     }
 }

.SH Output:

 Got: 'H'. Got again: 'H'.

.SH See also

   sungetc moves the next pointer in the input sequence back by one
           \fI(public member function of std::basic_streambuf<CharT,Traits>)\fP
   get     extracts characters
           \fI(public member function)\fP
   peek    reads the next character without extracting it
           \fI(public member function)\fP
   putback puts a character into input stream
           \fI(public member function)\fP
